package Com.Ring.TradingMobile;

import Com.Ring.TradingMobile.Lib.Common;
import Com.Ring.TradingMobile.Lib.Session;
import Com.Ring.TradingMobile.SQLite.DBManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class TradingMobileActivity extends Activity {
	/** Called when the activity is first created. */

	private static final String TAG = "TradingMobileTAG";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Log.d(TAG, "On Create");
		InitCreateDB();
		final Button btnDanhMuc = (Button) findViewById(R.id.btnDanhMuc);

		btnDanhMuc.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						DanhMucActivity.class);
				startActivity(intent);
			}

		});
		final Button btnThiTruong = (Button) findViewById(R.id.btnThiTruong);

		btnThiTruong.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						ThiTruongActivity.class);
				Bundle senderBundle = new Bundle();

				senderBundle.putStringArray(Common.KeyIntentThiTruong,
						new String[]{"1", Common.DanhMucRoot, "0"});// 1: ma thi
																	// truong,
																	// danhmucroot:
																	// tendanhmuc,
																	// 0:
																	// ActivityMain
				intent.putExtras(senderBundle);
				startActivity(intent);
			}

		});
		final Button btnHistory = (Button) findViewById(R.id.btnHistory);

		btnHistory.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						HistoryActivity.class);
				startActivity(intent);
			}

		});
		final Button btnSetting = (Button) findViewById(R.id.btnSetting);

		btnSetting.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						SettingActivity.class);
				startActivity(intent);
			}

		});
		final Button btnLogin = (Button) findViewById(R.id.btn_Login);

		btnLogin.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						DangNhapActivity.class);
				startActivity(intent);
			}
		});

		if (Session.IsLogin) {
			Intent home = new Intent(getBaseContext(),
					TradingMobileLoggedActivity.class);
			startActivity(home);
			// btnLogin.setVisibility(View.GONE);
			return;
		}

		final Button btnExit = (Button) findViewById(R.id.btnBack);

		btnExit.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
				
			}
		});

	}

	// public void doWork() {
	// runOnUiThread(new Runnable() {
	// public void run() {
	// try{
	// TextView txtCurrentTime= (TextView)findViewById(R.id.txtTimer);
	// DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
	// Date date = new Date();
	// txtCurrentTime.setText(dateFormat.format(date));
	// }catch (Exception e) {}
	// }
	// });
	// }
	// class CountDownRunner implements Runnable{
	// // @Override
	// public void run() {
	// while(IsRunning){
	// try {
	// doWork();
	// Thread.sleep(1000);
	// Log.d(TAG,"Retail");
	// } catch (InterruptedException e) {
	// Thread.currentThread().interrupt();
	// }catch(Exception e){
	// }
	//
	// }
	// Log.d(TAG,"Retail");
	// }
	// }

	@Override
	protected void onStart() {
		Log.d(TAG, "On Start");
		super.onStart();
	}

	@Override
	protected void onPause() {
		Log.d(TAG, "On Pause");
		super.onPause();
	}

	@Override
	protected void onStop() {
		Log.d(TAG, "On Stop");
		super.onStop();
	}

	private void InitCreateDB() {
		DBManager db = new DBManager(this);
		try {
			db.InsertDanhMuc(Common.DanhMucRoot);
			db.InitDataConfig();
		} catch (Exception ex) {
			Log.d(TAG, ex.toString());
		} finally {
			db.close();
		}
	}

	@Override
	protected void onDestroy() {
		Log.d(TAG, "On Destroy");
		super.onDestroy();
	}

}